<template>
	<view>
		<!-- 导航栏 -->
		<scroll-view scroll-x class="nav text-center" :class="'bg-'+basic.color">
			<view class="cu-item" :class="tab==='0'?'text-green cur':''" @tap="tabSelect('0')">程序参数</view>
			<view class="cu-item" :class="tab==='1'?'text-green cur':''" @tap="tabSelect('1')">7日盈亏比</view>
		</scroll-view>
		
		<!-- 内容区 -->
		<view v-if="tab==='0'">
			<!-- 程序参数 -->
			<view class="solids-bottom padding-xs flex align-center">
				<view class="padding">
					<view>程</view>
					<view>序</view>
					<view>参</view>
					<view>数</view>
				</view>
				<view class="flex-sub">
					<view class="cu-list menu">
						<view class="cu-item">
							<view class="content">
								<view>利润间距</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.profit }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>急速止盈/止损</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.rapid }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>恐慌与贪婪指数</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.fgi }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>交易所可用余额</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.balance }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>初始金额</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.init_balance }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>计价货币</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.ccy }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>手续费</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.commission }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>持仓模式</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.isolated }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>最低保证金</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.min_margin }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>账户阀值(低于时退出程序)</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.threshold }}</text>
							</view>
						</view>
						<view class="cu-item">
							<view class="content">
								<view>最小DGS数量</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ argument_data.min_dgs_number }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 程序参数 -->
			
			<!-- 已过滤(最小DGS数) -->
			<view v-if="argument_data.filtration_min_dgs_number.length > 0">
				<view :class="'bg-'+basic.color">
					<view class="text-center padding">已过滤(最小DGS数)</view>
				</view>
				<view v-for="(item, index) in argument_data.filtration_min_dgs_number" :key="index" class="text-center padding">【{{ item.timestamp }}】 {{ item.symbol }}</view>
				<view style="margin-bottom: 45px;" />
			</view>
			<!-- 已过滤(最小DGS数) -->
			
		</view>
		<view v-else>
			<!-- 7日盈亏比 -->
			<view v-if="profitLoss_data.length > 0" class="solids-bottom padding-xs flex align-center">
				<view class="flex-sub">
					<view class="cu-list menu">
						<view v-for="(value, index) in profitLoss_data" :key="index" class="cu-item">
							<view class="content">
								<view>{{ value.symbol }}</view>
							</view>
							<view class="action">
								<text class="text-sm">{{ value.realizedPnl }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else>
				<view class="padding-xs flex align-center">
					<view class="flex-sub text-center">
						<view class="padding" style="font-size: 14px">无7日历史交易数据</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mineArgument } from '@/api/dgs/dgs.js'
	import { mineProfitLoss } from '@/api/basic/basic.js'
	export default {
		props: {
			basic: {},
			vprogramstate: {}
		},
		data() {
			return {
				tab: '0',
				argument_data: {},
				profitLoss_data: []
			}
		},
		mounted() {
			uni.showLoading({
				title: '加载中...',
			})
			console.log('我的')
			this.getArgument()
			setTimeout(function () {
				uni.hideLoading();
			}, 2000);
		},
		methods: {
			// 导航栏切换
			tabSelect(tabId) {
				uni.showLoading({
					title: '加载中...',
				})
				if (tabId === '0') {
					this.getArgument()
					this.tab = tabId
				} else if (tabId === '1') {
					if (this.vprogramstate.pan_opening === '0') {
						this.getProfitLoss()
						this.tab = tabId
					} else {
						setTimeout(function () {
							uni.hideLoading();
						}, 1000);
						uni.showToast({ icon:'none', title: '当前不是实盘模式' })
					}
				}
				setTimeout(function () {
					uni.hideLoading();
				}, 1000);
			},
			// 获取程序参数
			getArgument() {
				var _this = this
				uni.getStorage({
					key:_this.basic.exchange_domain + _this.basic.strategy_name,
					success(resVisit) {
						mineArgument(resVisit.data.ip_address, `${_this.basic.exchange_domain}/${_this.basic.strategy_name}`, resVisit.data.access).then((res) => {
							console.log('获取我的页面程序参数数据', res)
							_this.argument_data = res.data
							setTimeout(function () {
								uni.hideLoading();
							}, 2000);
						})
						
					},fail(errVisit) {
						console.log('我的页面程序参数获取token失败.')
						uni.showToast({ icon:'none', title: 'Token获取失败' })
						setTimeout(function () {
							uni.reLaunch({
								url: '/pages/home/home'
							});
						}, 2000)
					}
				})
			},
			// 获取7日盈亏比
			getProfitLoss() {
				var _this = this
				uni.getStorage({
					key:_this.basic.exchange_domain + _this.basic.strategy_name,
					success(resVisit) {
						mineProfitLoss(resVisit.data.ip_address, resVisit.data.access, {
							exchange_domain: _this.basic.exchange_domain, strategy_name: _this.basic.strategy_name
						}).then(res => {
							console.log('获取我的页面7日盈亏比数据', res)
							_this.profitLoss_data = res.data
							setTimeout(function () {
								uni.hideLoading();
							}, 2000);
						})
						
					},fail(errVisit) {
						console.log('我的页面7日盈亏比获取token失败.')
						uni.showToast({ icon:'none', title: 'Token获取失败' })
						setTimeout(function () {
							uni.reLaunch({
								url: '/pages/home/home'
							});
						}, 2000)
					}
				})
			}
		}
	}
</script>

<style>

</style>
